﻿using CodeMan.Domain.ClassGens;
using Microsoft.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;

namespace CodeMan.EntityFrameworkCore
{
    public static class CodeManDbContextModelCreatingExtensions
    {
        public static void ConfigureCodeMan(this ModelBuilder builder)
        {
            Check.NotNull(builder, nameof(builder));

            /* Configure your own tables/entities inside here */

            builder.Entity<ClassAttribute>(b =>
            {
                b.ToTable("ClassAttribute");

                //Configure the base properties
                //b.ConfigureByConvention();

                b.HasKey(c => new { c.ClassGenId, c.AName });
            });


            builder.Entity<ClassGen>(b =>
            {
                b.ToTable("ClassGen");

                //Configure the base properties
                //b.ConfigureByConvention();

                //Configure other properties (if you are using the fluent API)
                b.HasKey(a => a.Id);
                b.Property(a => a.Id).ValueGeneratedOnAdd();
                b.Property(a => a.Name)
                    .IsRequired(true);
                b.Property(a => a.Namespace)
                    .IsRequired(false);
                b.Property(a => a.Desc)
                   .IsRequired(false);
                b.Property(a => a.Type)
                   .IsRequired(true);
                b.Property(a => a.Complete)
                   .IsRequired(true);
            });

            //builder.Entity<YourEntity>(b =>
            //{
            //    b.ToTable(CodeManConsts.DbTablePrefix + "YourEntities", CodeManConsts.DbSchema);
            //    b.ConfigureByConvention(); //auto configure for the base class props
            //    //...
            //});
        }
    }
}
